<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>
    <input type="text" placeholder="姓名" v-model="emp.name">
    <input type="text" placeholder="工资" v-model="emp.salary">
    <input type="text" placeholder="工作" v-model="emp.job">
    <input type="button" value="添加" @click="f()">
    <table border="1">
        <caption>员工列表</caption>
        <tr>
            <th>名字</th>
            <th>工资</th>
            <th>工作</th>
        </tr>
        <tr v-for="p in arr">
            <td>{{p.name}}</td>
            <td>{{p.salary}}</td>
            <td>{{p.job}}</td>
        </tr>
    </table>
</div>
<!--引入Vue框架-->
<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
<script>
    let v=new Vue({
             el:"body>div",
             data:{
                arr:[{name:"张三",salary:3000,job:"销售"},
                    {name:"李四",salary:4000,job:"人事"},
                    {name:"王五",salary:10000,job:"程序员"}],
                emp:{name:"",
                    salary:"",
                    job:""
                }
             },
             methods:{
                 f(){
                     //push()是javascript中数组里面添加的方法
                     //JSON.parse(JSON.stringify(v.emp))创建了一个新的对象添加到数组中
                     //此时emp对象的值发生了改变和数组中的新对象是无关的,
                     //这种复制出来的和原对象无关二点凡是称为深拷贝(有关系的是浅拷贝)
                   v.arr.push(JSON.parse(JSON.stringify(v.emp)))
                 }
             }
         })
</script>
</body>
</html>